home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’93
/
sort
/
Source
/
sortmain.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-17
|
4KB
|
210 lines
/*****
* sortmain.c
*
*
*
*****/
#include <Quickdraw.h>
#include <Windows.h>
#include <Dialogs.h>
#include <Memory.h>
#include <Fonts.h>
#include <Events.h>
#include <OSEvents.h>
#include <Menus.h>
#include <Desk.h>
#include <ToolUtils.h>
#include <TextEdit.h>
#include <DiskInit.h>
#ifdef THINK_C
#include <Think.h>
#endif
#include "sortMenus.h"
#include "sortWindow.h"
#include "sort.h"
#include "notif.h"
#include "acur.h"
Boolean done;
#define ACUR_ID 128
extern WindowPtr sortWindow;
extern Rect dragRect;
void InitMacintosh(void);
void HandleMouseDown (EventRecord *theEvent);
/****
* InitMacintosh()
*
* Initialize all the managers & memory
*
****/
void InitMacintosh(void)
{
MaxApplZone();
#ifdef THINK_C
InitGraf(&thePort);
#else /* applec */
InitGraf(&qd.thePort);
#endif /* applec */
qd.randSeed = TickCount();
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
Initacur(ACUR_ID);
}
/* end InitMacintosh */
/****
* HandleMouseDown (theEvent)
*
* Take care of mouseDown events.
*
****/
void HandleMouseDown (EventRecord *theEvent)
{
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode)
{
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inMenuBar:
AdjustMenus();
SetCursor(&qd.arrow);
HandleMenu(MenuSelect(theEvent->where));
break;
case inDrag:
if (theWindow == sortWindow)
DragWindow(sortWindow, theEvent->where, &dragRect);
break;
case inContent:
if (theWindow == sortWindow)
{
if (theWindow != FrontWindow())
SelectWindow(sortWindow);
else
InvalRect(&sortWindow->portRect);
}
break;
case inGoAway:
if (theWindow == sortWindow &&
TrackGoAway(sortWindow, theEvent->where))
HideWindow(sortWindow);
break;
}
}
/* end HandleMouseDown */
/****
* HandleEvent()
*
* The main event dispatcher. This routine should be called
* repeatedly (it handles only one event).
*
*****/
void HandleEvent(void)
{
int ok;
EventRecord theEvent;
SystemTask (); /* Handle desk accessories */
ok = WaitNextEvent (everyEvent, &theEvent, 1L, NULL);
if (ok)
switch (theEvent.what)
{
case mouseDown:
HandleMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
if ((theEvent.modifiers & cmdKey) != 0) {
AdjustMenus();
SetCursor(&qd.arrow);
HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
}
break;
case updateEvt:
BeginUpdate(sortWindow);
DrawSort(((WindowPeek) sortWindow)->hilited);
EndUpdate(sortWindow);
break;
case activateEvt:
break;
case diskEvt:
if ( HiWord(theEvent.message) != noErr ) {
Point aPoint;
SetPt(&aPoint, 100, 199);
DIBadMount(aPoint, theEvent.message);
}
break;
case osEvt:
switch ((theEvent.message >> 24) & 0x0FF) { /* high byte of message */
case suspendResumeMessage: /* suspend/resume is also an activate/deactivate */
gInBackground = (theEvent.message & resumeFlag) == 0;
break;
default:
break;
}
}
}
/* end HandleEvent */
/*****
* main()
*
* This is where everything happens
*
*****/
main()
{
InitMacintosh();
SetUpMenus();
SetUpWindow();
if (init_data(numdataitems) != noErr) {
numdataitems = 2;
height=((((windowBounds.bottom - windowBounds.top) - numdataitems) -5)) / (numdataitems + 1);
init_data(numdataitems);
}
sorting = false;
gInBackground = false;
done = false;
for (;done == false;)
HandleEvent();
}
/* end main */